/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Manager;

import FrameWork.Global;
import FrameWork.Models.GLModel;
import FrameWork.Models.ModelLoaderOBJ;
import javax.media.opengl.GL2;

/**
 *
 * @author trong_000
 */

public class ResourceManager {
    public enum ECHESSPIECE{
        RED_GENERAL ,
        RED_ADVISOR1 ,
        RED_ADVISOR2 ,
        RED_ELEPHANT1,
        RED_ELEPHANT2,
        RED_HORSE1 ,
        RED_HORSE2 ,
        RED_CHARIOT1,
        RED_CHARIOT2,
        RED_CANNON1 ,
        RED_CANNON2 ,
        RED_SOLDIER1,
        RED_SOLDIER2,
        RED_SOLDIER3 ,
        RED_SOLDIER4 ,
        RED_SOLDIER5 ,
        BLUE_GENERAL,
        BLUE_ADVISOR1,
        BLUE_ADVISOR2,
        BLUE_ELEPHANT1,
        BLUE_ELEPHANT2,
        BLUE_HORSE1,
        BLUE_HORSE2,
        BLUE_CHARIOT1,
        BLUE_CHARIOT2,
        BLUE_CANNON1 ,
        BLUE_CANNON2,
        BLUE_SOLDIER1,
        BLUE_SOLDIER2,
        BLUE_SOLDIER3,
        BLUE_SOLDIER4,
        BLUE_SOLDIER5 
    }
    private static ResourceManager instance = null;
    
    protected ResourceManager(){
        init();
    }
    
    public static ResourceManager getInstance(){
        if(instance==null){
            instance = new ResourceManager();
        }
        return instance;
    }
    
    public GLModel ChessBoard;
    
    public GLModel RedGeneral; //Tuongs
    public GLModel BlueGeneral;
    public GLModel RedAdvisor; //Si
    public GLModel BlueAdvisor;
    public GLModel RedElephant; //Tuongj
    public GLModel BlueElephant;
    public GLModel RedHorse; //Ma
    public GLModel BlueHorse;
    public GLModel RedChariot; //Xe
    public GLModel BlueChariot;
    public GLModel RedCannon; //Phao
    public GLModel BlueCannon;
    public GLModel RedSoldier; //Chot
    public GLModel BlueSoldier;
    
    public void init(){
        GL2 gl =  Global.getIns().drawable.getGL().getGL2();
        ChessBoard = ModelLoaderOBJ.LoadModel("./models/BanCo.obj",
                            "./models/BanCo.mtl", gl);
        RedGeneral = ModelLoaderOBJ.LoadModel("./models/QuanCo/TuongDo.obj",
                            "./models/QuanCo/TuongDo.mtl", gl);
        BlueGeneral = ModelLoaderOBJ.LoadModel("./models/QuanCo/TuongDen.obj",
                            "./models/QuanCo/TuongDen.mtl", gl);
        RedAdvisor = ModelLoaderOBJ.LoadModel("./models/QuanCo/SiDo.obj",
                            "./models/QuanCo/SiDo.mtl", gl);
        BlueAdvisor = ModelLoaderOBJ.LoadModel("./models/QuanCo/SiDen.obj",
                            "./models/QuanCo/SiDen.mtl", gl);
        RedElephant = ModelLoaderOBJ.LoadModel("./models/QuanCo/TinhDo.obj",
                            "./models/QuanCo/MaDo.mtl", gl);
        BlueElephant = ModelLoaderOBJ.LoadModel("./models/QuanCo/TinhDen.obj",
                            "./models/QuanCo/MaDen.mtl", gl);
        RedHorse = ModelLoaderOBJ.LoadModel("./models/QuanCo/MaDo.obj",
                            "./models/QuanCo/MaDo.mtl", gl);
        BlueHorse = ModelLoaderOBJ.LoadModel("./models/QuanCo/MaDen.obj",
                            "./models/QuanCo/MaDen.mtl", gl);
        RedChariot = ModelLoaderOBJ.LoadModel("./models/QuanCo/XeDo.obj",
                            "./models/QuanCo/MaDo.mtl", gl);
        BlueChariot = ModelLoaderOBJ.LoadModel("./models/QuanCo/XeDen.obj",
                            "./models/QuanCo/MaDen.mtl", gl);
        RedCannon = ModelLoaderOBJ.LoadModel("./models/QuanCo/PhaoDo.obj",
                            "./models/QuanCo/PhaoDo.mtl", gl);
        BlueCannon = ModelLoaderOBJ.LoadModel("./models/QuanCo/PhaoDen.obj",
                            "./models/QuanCo/PhaoDen.mtl", gl);
        RedSoldier = ModelLoaderOBJ.LoadModel("./models/QuanCo/TotDo.obj",
                            "./models/QuanCo/TotDo.mtl", gl);
        BlueSoldier = ModelLoaderOBJ.LoadModel("./models/QuanCo/TotDen.obj",
                            "./models/QuanCo/TotDen.mtl", gl);
        
    }
    
    public GLModel getModelChessPiece(ECHESSPIECE cp){
        switch(cp){
            case RED_GENERAL:
                return RedGeneral;
            case RED_ADVISOR1: case RED_ADVISOR2:
                return RedAdvisor;
            case RED_CANNON1: case RED_CANNON2:
                return RedCannon;
            case  RED_CHARIOT1: case RED_CHARIOT2:
                return RedChariot;
            case RED_ELEPHANT1: case RED_ELEPHANT2:
                return RedElephant;
            case RED_HORSE1: case RED_HORSE2:
                return RedHorse;
            case RED_SOLDIER1: case RED_SOLDIER2: case RED_SOLDIER3: case RED_SOLDIER4: case RED_SOLDIER5:
                return RedSoldier;
            
            case BLUE_GENERAL:
                return BlueGeneral;
            case BLUE_ADVISOR1: case BLUE_ADVISOR2:
                return BlueAdvisor;
            case BLUE_CANNON1: case BLUE_CANNON2:
                return BlueCannon;
            case  BLUE_CHARIOT1: case BLUE_CHARIOT2:
                return BlueChariot;
            case BLUE_ELEPHANT1: case BLUE_ELEPHANT2:
                return BlueElephant;
            case BLUE_HORSE1: case BLUE_HORSE2:
                return BlueHorse;
            case BLUE_SOLDIER1: case BLUE_SOLDIER2: case BLUE_SOLDIER3: case BLUE_SOLDIER4:case BLUE_SOLDIER5:
                return BlueSoldier;
            
        }
        return null;
    }
}
